{template "common/header"}

<ul class="nav nav-tabs">
  <li {if $op == 'list'}class="active"{/if}>
     <a href="{php echo $this->createWebUrl('teacher',array('op'=>'list'))}" >讲师列表</a>
  </li>
  <li {if $op == 'post'}class="active"{/if}>
     <a href="{php echo $this->createWebUrl('teacher',array('op'=>'post'))}" >{if empty($info['id'])}添加讲师{else}修改讲师信息{/if}</a>
  </li>
</ul>
<style type="text/css">
	.xh-toast-block{ min-width: 300px; position:fixed; z-index: 9999; font-size: 18px; color: #e7e7e7; padding: 10px 20px; background: rgba(0,0,0,0.7); left: 50%; top: 50%; line-height: 40px; border-radius: 10px; text-align: center; margin-top: -30px; margin-left: -150px; }
	.modeladd li{
		padding-top: 5px;
		padding-bottom: 5px;
		list-style: none;
		width: 100%;
		float: left;
	}

	  .toast_block{
		  display: none;
	  }
	.toast_mask{
		background: rgba(0,0,0,0.3);
		position: fixed;
		z-index: 10000;
		top: 0;right: 0;left: 0;bottom: 0;
	}
	.toast_content{
		background: #ffffff;
		position: absolute;
		top: 0;right: 0;left: 0;bottom: 0;
		margin: auto;
		width: 200px;
		height: 200px;
		z-index: 20000;
		border-radius: 15px;
		overflow: hidden;
	}


</style>
{if $op == 'list'}
<div class="list-group">
	<p class="list-group-item " style="background-color: #D9EDF7">按条件搜索</p>
	<div active="list-group-item" style="border:1px solid #cecece">
		<form action="./index.php" method="get" class="form-horizontal">
			<input type="hidden" name="c" value="site">
			<input type="hidden" name="a" value="entry">
			<input type="hidden" name="m" value="goouc_class">
			<input type="hidden" name="do" value="teacher">
			<div class="form-group col-sm-3" style="margin-top:25px" >
				<label  class="col-sm-4 control-label" style="padding-right: 11px">讲师名称:</label>
				<div class="col-sm-8">
					<input type="text" name="kname" value="{$kname}" class="form-control" />
				</div>
			</div>
			<div class="form-group col-sm-3" style="margin-top:25px" >
				<label  class="col-sm-4 control-label" style="padding-right: 11px">城市:</label>
				<select class="col-sm-8" name="cityid" >
					<option value="">--请选择--</option>
					{loop $city $c}
					<option  value="{$c['id']}" {if $c['id'] == $cityid}selected = "selected"{/if} class="form-control" >{$c['name']}</option>
					{/loop}
				</select>
			</div>
			<div class="form-group col-sm-3" style="margin-top:25px" >
				<label  class="col-sm-4 control-label" style="padding-right: 11px">学科:</label>
				<select class="col-sm-8" name="subjectid" >
					<option value="">--请选择--</option>
					{loop $subject $s}
					<option  value="{$s['id']}" {if $s['id'] == $subjectid}selected = "selected"{/if} class="form-control" >{$s['name']}</option>
					{/loop}
				</select>
			</div>
			<div class="form-group col-sm-3" style="margin-top:25px" >
				<button class="btn btn-default" style="margin-left:140px"><i class="fa fa-search"></i> 搜索</button>
			</div>
		<div style="clear:both"></div>
		</form>
	</div>
</div>
<div class="row clearfix" >
<div class="col-md-12 column">
	<div class="list-group">
		<p  class="list-group-item " style="background-color: #D9EDF7" >讲师信息表</p>
			<div active="list-group-item" style="border:1px solid #cecece;">
				<table class="table table-hover table-bordered" style="margin-top:25px;width:98%" align="center">
					<thead>
						<tr>
							<th>
								{if $paixu == 2}
								<a href="{php echo $this->createWebUrl('teacher',['op'=>'list','paixu'=>1])}">
									排序 <img src="{php echo MODULE_URL.'images/up.png'}" alt="" style="height: 14px;">
								</a>
								{elseif $paixu == 1}
								<a href="{php echo $this->createWebUrl('teacher',['op'=>'list','paixu'=>2])}">
									排序 <img src="{php echo MODULE_URL.'images/down.png'}" alt="" style="height: 14px;">
								</a>
								{/if}
							</th>
							<th>讲师名称</th>
							<!--<th>头像</th>-->
							<th>所属分校（城市）</th>
							<th>教授学课</th>
							<th>状态</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody>
						{loop $teacherlist $row}
						<tr>
							<td class="paixu" id="{$row['id']}">{$row['order']}</td>
							<td>{$row['name']}</td>
							<td>{$row['cityname']['name']}</td>
							<td>{$row['subjectname']['name']}</td>
							<td style="width:15%"><div class="btn {if $row['status'] == 0}btn-danger{else}btn-info{/if}" data="{$row['id']}" onclick="voidtypestatus(this)">{if $row['status'] == 0}不显示{elseif $row['status'] == 1}显示{/if}</div></td>
							<td>
								<a data="{$row['id']}" class="btn btn-info dianwo" onclick="get_img('{$_W['attachurl']}{$row['headimg']}')">查看</a>
				                <a href="{php echo $this->createWebUrl('teacher',array('op'=>'post','id'=>$row['id']))}" class="btn btn-info">编辑</a>
								<a href="{php echo $this->createWebUrl('teacher',array('op'=>'delete','id'=>$row['id']))}" class="btn btn-danger">删除</a>
				            </td>

						</tr>
						{/loop}
					</tbody>
				</table>

				<script type="text/javascript">
					function voidtypestatus(obj){
						var obj = $(obj);
						var id = obj.attr('data');
						if(obj.hasClass('btn-danger')){
							var sta = 1;
						}else{
							var sta = 0;
						}
						$.ajax({
							type:'post',
							url:"{php echo $this->createWebUrl('teacher',array('op'=>'changestatus'))}",
							data:{id:id,sta:sta},
							success:function(res){
								var res = JSON.parse(res);
								if(res.success == 1){
									if(sta == 1){
										obj.removeClass('btn-danger');
										obj.addClass('btn-info');
										obj.html('显示');
									}else{
										obj.removeClass('btn-info');
										obj.addClass('btn-danger');
										obj.html('不显示');
									}
								}else{
									alert(res.mess);
								}
							}
						});
					}
					function get_img(url) {
						$('#seeimg').attr("src", url);
						$('.toast_block').show();
					}


				</script>
			</div>
		{$page}
	</div>
</div>
</div>
<script>
	$(function(){
		$('.paixu').click(function(){
			if(!$(this).is('.input')){
				$(this).addClass('input').html('<input type="text" id="'+$(this).attr("id") +'" style="width: 50px;" value="'+ $(this).text() +'" />').find('input').focus().blur(function(){
					var order=$(this).val();
					var id=$(this).attr("id");
					$.ajax({
						type: 'POST',
						url: "{php echo $this->createWebUrl('teacher',array('op'=>'sort'))}",
						data: {id:id,order:order},
						success:function(res){
							var res = JSON.parse(res);
							location.reload();
						}
					});
					$(this).parent().removeClass('input').html($(this).val() || 0);
				});
			}
		}).hover(function(){
			$(this).addClass('hover');
		},function(){
			$(this).removeClass('hover');
		});
	});
</script>
{elseif $op == 'post'}
<div class="list-group">
<p href="#" class="list-group-item" style="background-color: #D9EDF7;border:1px solid #D9EDF7;color:#31708F">讲师设置</p>
<div active="list-group-item " style="border:1px solid #cecece">
	<form action="" method="post" class="form-horizontal" style="padding:0 150px 0 50px;">
		<div class="form-group" style="margin-top:25px">
			<label  class="col-sm-2 control-label"><span style="color: red;">*</span>名称</label>
			<div class="col-sm-10">
				<input type="text" name="name" value="{$info['name']}"    class="form-control" style="width:98%"/>
				<span class="help-block">若讲师分管多个校区，请创建新的讲师信息，例如:李老师(郑州)、李老师(洛阳)</span>
			</div>
		</div>
		<!--  待定-->
		<div class="form-group" style="margin-top:25px">
			<label  class="col-sm-2 control-label">讲师头像</label>
			<div class="col-sm-10">
				<div style="width:98%">
				{php echo tpl_form_field_image('headimg',$info['headimg'])}
				</div>
				<span class="help-block">建议图片尺寸：164*164(保持头像宽高比例为1:1)</span>
			</div>
		</div>
		<div class="form-group" style="margin-top:25px">
			<label  class="col-sm-2 control-label">讲师简介</label>
			<div class="col-sm-10">
				<input type="text" name="desc" value="{$info['desc']}" class="form-control" style="width:98%" maxlength="150">
				<span class="help-block">教师简介，最多150个字符</span>
			</div>
		</div>
		<div class="form-group" style="margin-top:25px">
			<label  class="col-sm-2 control-label">手机号</label>
			<div class="col-sm-10">
				<input type="text" id="mobile" name="mobile" value="{$info['mobile']}" class="form-control" style="width:98%" maxlength="150" onblur="checkM();">
				<span class="help-block">温馨提示：手机号小程序端与后台填写一致方能在手机端查看学生作业</span>
			</div>
		</div>

		<div class="form-group" style="margin-top:25px">
			<label  class="col-sm-2 control-label"><span style="color: red;">*</span>城市</label>
			<div class="col-sm-10">
				<select  name="cityid"  style="width:98%">
					<option value="">--请选择城市--</option>
					{loop $city $c}
					<option value="{$c['id']}" {if $c['id'] == $info['cityid']}selected{/if}>{$c['name']}</option>
					{/loop}
				</select>
				<span class="help-block"></span>
			</div>
		</div>
		<div class="form-group" style="margin-top:25px">
			<label  class="col-sm-2 control-label"><span style="color: red;">*</span>学科</label>
			<div class="col-sm-10">
			<select  name="subjectid"  style="width:98%">
				<option value="">--请选择学科--</option>
				{loop $subject $s}
				<option value="{$s['id']}" {if $s['id'] == $info['subjectid']}selected{/if}>{$s['name']}</option>
				{/loop}
			</select>
				<span class="help-block"></span>
			</div>
		</div>
		<div class="form-group ">
			<label  class="col-sm-2 control-label">讲师状态</label>
	            <div class=" col-sm-10" style="padding-left:25px">
	            	<label class="radio-inline">
	                <input type="radio" name="status"  value='1' title="显示" {if $info['status'] == '1'}checked{/if}> 显示
					</label>
	              	<label class="radio-inline">
	                <input type="radio" name="status"  value='0' title="不显示" {if empty($info['id'])}checked{/if} {if $info['status'] == '0'}checked{/if}> 不显示
	              	</label>
					<span class="help-block">若不选择，默认为不显示</span>
				</div>
	    </div>
		<div class="form-group" style="margin-top:25px">
			<label class="col-sm-2 control-label">排序</label>
			<div class="col-sm-10">
				<input type="number" name="order" value="{if empty($info['order'])}0{else}{$info['order']}{/if}"    class="form-control" style="width:98%"/>
				<span class="help-block	">请填写0到100的数字，数字越大排序越靠前</span>
			</div>
		</div>
		<input type="hidden" name="token" value="{$_W['token']}">
		<div style="float: right;margin:10px">
			<input type="submit" name="submit" value="保存设置" class="btn btn-info" onclick="return check();">
		</div>
		<div style="clear: both;"></div>
	</form>
</div>
</div>
<script>
	function check() {
		var flag = true;
		if($('input[name="name"]').val() == ''){
            flag = false;
            xhToast('请填写老师名称');
            return flag;
        }
		if($('input[name="mobile"]').val() == 0){
			flag = false;
			xhToast('请填写手机号');
			return flag;
		}
        if($('select[name="cityid"]').val() == ''){
            flag = false;
            xhToast('请选择老师所在城市');
            return flag;
        }
        if($('select[name="subjectid"]').val() == ''){
            flag = false;
            xhToast('请选择老师所授科目');
            return flag;
        }
        if($('input[name="headimg"]').val() == ''){
            flag = false;
            xhToast('请设置老师头像');
            return flag;
        }
        if($('input[name="desc"]').val() == ''){
            flag = false;
            xhToast('请设置老师简介');
            return flag;
        }
        return flag;
    }
    //公用提示窗
    function xhToast(_text){
        $('body').append("<div class='xh-toast-block'>"+_text+"</div>");
        setTimeout(function(){
            $('.xh-toast-block').remove();
        },2000);
    }
	function checkM() {
		var mobile = $('input[name="mobile"]').val();
		var reg =/^[1][3,4,5,6,7,8,9][0-9]{9}$/;
		if(!reg.test(mobile)){
			flag = false;
			xhToast('请输入有效的手机号码');
			return flag;
		}
	}
</script>
{/if}

{template "common/footer"}
<div class="toast_block ">
	<div class="toast_mask">	</div>
	<div class="toast_content">
		<img id="seeimg" src="" style="width:200px;height: auto;">
	</div>
</div>
<script>
	$(function(){
		$('.toast_mask').click(function(){
			console.log('1111');
			$('.toast_block').hide();
		})
	})
</script>